Skip to content

플러그인이 동작하는 걸음 단위에 대한 옵션 추가#2

Open
SugyoIn-LBSTech wants to merge 5 commits intomasterfrom
split_noti
Open

플러그인이 동작하는 걸음 단위에 대한 옵션 추가#2
SugyoIn-LBSTech wants to merge 5 commits intomasterfrom
split_noti

Conversation

@SugyoIn-LBSTech
Copy link

  • 디바이스 데이터 베이스에 저장할지 여부를 선택하는 storeHistory 옵션 추가.
  • 디바이스 데이터 베이스에 저장하는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
  • Flutter로 보내는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.

Flutter side code를 기존 MethodChannel을 사용한 data streaming 방식에서 EventChannel로 변경.
- 디바이스 데이터 베이스에 저장할지 여부를 선택하는 storeHistory 옵션 추가.
- 디바이스 데이터 베이스에 저장하는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
- Flutter로 보내는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
- LbsPedometerPlugin.java의 static 변수들 member 변수로 전환.
- Plugin의 성격상 MethodChannel 사용에서 EventChannel 사용으로 변경.
- ServiceManager와 ServiceSensor가 사용하던 같은 상수들을 ServiceManager로 병합 및 공유.
- Flutter에서 추가된 옵션 처리 부분 추가.
private boolean isGPSEnable;

LocationHandler(Context context, Activity activity, LbsPedometerPlugin instance) {
LocationHandler(Context context, Activity activity) {
Copy link
Author

@SugyoIn-LBSTech SugyoIn-LBSTech May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요 인자 제거.

private Context context;
private Activity activity;
private LbsPedometerPlugin plugin;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미사용 멤버 제거.

private int resultStepsUnit;
private int storeStepsUnit;
private EventChannel.EventSink eventSink;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 옵션 적용.

this.storeHistory = storeHistory;
this.resultStepsUnit = resultStepsUnit;
this.storeStepsUnit = storeStepsUnit;
this.eventSink = eventSink;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 옵션 적용.

static final int MSG_SENSOR_TRIGGER = 0XAA2;
static final int MSG_LIFECYCLE_START = 0XAA3;
static final int MSG_LIFECYCLE_STOP = 0XAA4;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.


private Context context;
private Activity activity;
private LbsPedometerPlugin plugin;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미사용 멤버 제거.


try {
Message msg = Message.obtain(null, what);
Message msg = Message.obtain(null, what, obj);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 옵션 적용.

plugin.sendDataToFlutter(
sqlController.getCurrentWhereStep(ServiceSensor.currentSavedStepCnt)
);
eventSink.success(msg.obj);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MethodChannel에서 EventChannel로 변경.


private boolean storeHistory;
private int resultStepsUnit;
private int storeStepsUnit;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 옵션 적용.

Comment on lines 61 to 85
// ==================================== anonymous class =====================================
// message handler - APP 으로부터의 메세지를 다루는 익명 클래스
@SuppressLint("HandlerLeak")
private Messenger messenger = new Messenger(new Handler(){
private Messenger messenger = new Messenger(new Handler() {
@Override
public void handleMessage(Message msg) {
int data = msg.what;
switch (data){
case MSG_INIT:
switch (data) {
case ServiceManager.MSG_INIT:
Log.i("PEDOLOG_SS", "received msg: MSG_INIT");
appMessenger = msg.replyTo;
Map args = (Map) msg.obj;
storeHistory = (boolean) args.get("storeHistory");
resultStepsUnit = (int) args.get("resultStepsUnit");
storeStepsUnit = (int) args.get("storeStepsUnit");
sensorStart();
break;
case MSG_LIFECYCLE_START:
case ServiceManager.MSG_LIFECYCLE_START:
Log.i("PEDOLOG_SS", "received msg: MSG_LIFECYCLE_START");
appMessenger = msg.replyTo;
break;
case MSG_LIFECYCLE_STOP:
case ServiceManager.MSG_LIFECYCLE_STOP:
Log.i("PEDOLOG_SS", "received msg: MSG_LIFECYCLE_STOP");
appMessenger = null;
break;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.


break;
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flutter에 가는 알림과 디바이스 데이터 베이스에 저장하는 단위의 분할로 인해 기존 sqlController에 저장되어있던 내용을 보내는 것에서 resultStepsUnit에 맞게 들어온 위치 정보를 obj로 보내는 형식으로 변경.

onAndroidResumed: onAndroidResume,
resultStepsUnit: 3,
storeHistory: true,
storeStepsUnit: 10,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 옵션 적용.


const String _CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter'; No newline at end of file
const String _METHOD_CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter/method';
const String _EVENT_CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter/event'; No newline at end of file
Copy link
Author

@SugyoIn-LBSTech SugyoIn-LBSTech May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 MethodChannel을 MethodChannel과 EventChannel로 분리.

final MethodChannel _channel = MethodChannel(_CHANNEL_NAME);
class _PedometerController {
final MethodChannel _channel = MethodChannel(_METHOD_CHANNEL_NAME);
final EventChannel _eventChannel = EventChannel(_EVENT_CHANNEL_NAME);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 MethodChannel을 MethodChannel과 EventChannel로 분리.

print('종료 이후 이전 기록 가져오기의 결과가 비어 있습니다.');
return null;
}
}
Copy link
Author

@SugyoIn-LBSTech SugyoIn-LBSTech May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • call.method가 _MTD_TAKE_STEPS일 경우의 로직은 EventChannel로 변경하면서 EventChannel의 listen()함수로 넘어감.
  • 또한 stop()에 있던 로직을 call.method가 "onCancel"일 때로 옮겨옴. Android 코드에서 EventChannel의 구독이 취소될때 불림.


String _androidNotificationTitle = 'GPS 위치정보 추적중';
String _androidNotificationContent = '백그라운드에서 현재 위치를 지속적으로 추적하고 있습니다';
StreamSubscription _pedometerStream;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventChannel의 broadcastStream 구독 객체.

'storeHistory': storeHistory ?? true,
'resultStepsUnit': resultStepsUnit ?? storeStepsUnit ?? 10,
'storeStepsUnit': storeStepsUnit ?? resultStepsUnit ?? 10,
}).listen((stepData) => pedometer._onTakeStep(StepData.fromMap(stepData)));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 MethodCallHandler의 _MTD_TAKE_STEPS의 경우 로직을 옮겨옴.

}
}
void stop() => _pedometerStream?.cancel();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MethodCallHandler의 "onCancel"의 경우로 로직 이전.
Android 코드에서 EventChannel의 구독이 취소될때 불림.


const String _MTD_STOP = 'stop';

const String _MTD_TAKE_STEPS = 'takeSteps';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미사용 상수 제거.

/// 안드로이드 한정으로 [onAndroidResumed]에서 onResume의 콜백 처리를 한다.
/// 마찬가지로 안드로이드 한정으로 [resultStepsUnit]과 [storeStepsUnit]는 각각 Flutter로 데이터를 보내는 걸음 단위와 디바이스 데이터 베이스에 저장하는 걸음 단위를 의미한다.
/// 예를 들어 [resultStepsUnit]이 3이고 [storeStepsUnit]가 10이면 매 3걸음 마다 [onTakeStep]이 불리며 10걸음마다 디바이스 데이터 베이스에 데이터를 저장한다.
/// [resultStepsUnit]와 [storeStepsUnit] 둘 중 하나의 값 많이 정의 되더라도 다른 값 또한 같은 값으로 정의된며 기본값은 둘 다 10이다.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옵션 추가로 인한 주석 변경.

);
return null;
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옵션 추가 적용.


/// permission 을 요청하는 함수
Future<void> requestPermission() async => _controller.requestPermission();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단순 함수 위치 이동.

@required String content,
}) {
if (Platform.isIOS) return;
return _controller.setAndroidNotification(title: title, content: content);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단순 함수 위치 이동.

Future<List<StepData>> get history {
if (Platform.isIOS) return null;
return _controller.getHistory();
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHistory 함수를 getter 함수로 변경.

///
///
/// @return type : [Coordinate]
Future<Coordinate> get location => _controller.getLocation();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLocation 함수를 getter 함수로 변경.

Future<void> start({OnTakeStep onTakeStep, OnAndroidResumed onAndroidResumed}) {
/// @return type : [AuthorizationState]
Future<AuthorizationState> get authorizationState =>
_controller.getAuthorizationState();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAuthorizationState 함수를 getter 함수로 변경.

return _controller.getLocation();
}
@Deprecated('Effective Dart문서에 따라 getter를 쓰기로합니다. 2.x.x 이후 사라집니다.')
Future<Coordinate> getLocation() => _controller.getLocation();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getter 함수로 변경.

}
@Deprecated('Effective Dart문서에 따라 getter를 쓰기로합니다. 2.x.x 이후 사라집니다.')
Future<AuthorizationState> getAuthorizationState() async =>
_controller.getAuthorizationState();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getter 함수로 변경.

}

} No newline at end of file
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getter 함수로 변경.

private final int MSG_INIT = 0XAA1;
private final int MSG_SENSOR_TRIGGER = 0XAA2;
private final int MSG_LIFECYCLE_START = 0XAA3;
private final int MSG_LIFECYCLE_STOP = 0XAA4;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant